package com.gmrz.uap.config;

import com.alibaba.csp.sentinel.adapter.servlet.CommonFilter;
import com.gmrz.uap.TenantMapper;
import com.gmrz.uap.aop.SystemBlocker;
import com.gmrz.uap.aop.SystemInterceptor;
import com.gmrz.uap.service.TenantService;
import com.gmrz.uap.service.impl.TenantServiceImpl;
import com.gmrz.uap.servlet.SystemServlet;
import com.google.inject.Scopes;
import com.google.inject.matcher.Matchers;
import com.google.inject.servlet.ServletModule;
import com.mybatisflex.core.MybatisFlexBootstrap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author Wang Haifeng
 */
public class WebModule extends ServletModule {
    private static final Logger log = LoggerFactory.getLogger(WebModule.class);

    @Override
    protected void configureServlets() {

        log.info("WebModule configureServlets");
        serve("/").with(SystemServlet.class);

        // 绑定Sentinel的Servlet过滤器
        bind(CommonFilter.class).in(Scopes.SINGLETON);
        filter("/*").through(CommonFilter.class);


        bindInterceptor(Matchers.any(), Matchers.annotatedWith(SystemInterceptor.class), new SystemBlocker());

        bind(TenantMapper.class).toInstance(MybatisFlexBootstrap.getInstance().getMapper(TenantMapper.class));
        bind(TenantService.class).to(TenantServiceImpl.class);

        // requestInjection(Aspects.aspectOf(SecuredMethodAspect.class));
    }
}
